package logic

import (
	"context"
	"meituan-waimai/models/mysql"

	"meituan-waimai/meituanrpc/internal/svc"
	"meituan-waimai/meituanrpc/meituanrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShoppingCardListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShoppingCardListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShoppingCardListLogic {
	return &ShoppingCardListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShoppingCardListLogic) ShoppingCardList(in *meituanrpc.ShoppingCardListRequest) (*meituanrpc.ShoppingCardListResponse, error) {
	// todo: add your logic here and delete this line
	var shoppingCardList []mysql.ShoppingCard
	mysql.DB.Where("user_id = ?", in.UserId).Find(&shoppingCardList)
	var list []*meituanrpc.ShoppingCardList
	for _, card := range shoppingCardList {
		slice := meituanrpc.ShoppingCardList{
			UserId:        int64(card.UserId),
			GoodsId:       int64(card.GoodsId),
			GoodsNum:      int64(card.GoodsNum),
			ShoppingTotal: float32(card.ShoppingTotal),
		}
		list = append(list, &slice)
	}
	return &meituanrpc.ShoppingCardListResponse{
		List: list,
	}, nil
}
